/**
 * Created by joy on 21/09/2017.
 */
import CommonUtil from '../../common/utils/CommonUtil'
import prompt from 'prompt'
import RegUtil from '../../common1/utils/RegUtil'
import HttpRequestHelper from '../../common/helpers/HttpRequestHelper'

export default async () => {
  const schema = {
    properties: {
      address: {
        description: 'Enter address you want to check',
        type: 'string',
        required: true,
        default: '1G7BVfa6Uum3ZhANNFG8BzmVGGRm3Zkk8U'
      },
    }
  }

  const args = await CommonUtil.getArgsFromConsole(prompt, schema)
  let { address } = args
  const httpRequestHelper = new HttpRequestHelper()
  const { data } = await httpRequestHelper.get(`https://bitinfocharts.com/bitcoin cash/address/${address}`)
  const results = RegUtil.findAll(/<tr><td>Sent:<\/td><td><p class="text-error" style="display:inline">(.{1,10})<span class='muteds'>(.{1,6})<\/span> BCH/, data)
  const results2 = RegUtil.findAll(/Balance: <div style="display:inline-block" itemprop="offers" itemscope itemtype="http:\/\/schema.org\/Offer"><b>(.{1,10})<span class='muteds'>(.{1,10})<\/span> BCH/, data)
  const results3 = RegUtil.findAll(/Received:<\/td><td><p class="text-success" style="display:inline">(.{1,10})<span class='muteds'>(.{1,10})<\/span> BCH/, data)
  logger.info({
    out: results[0][1] + results[0][2],
    balance: results2[0][1] + results2[0][2],
    in: results3[0][1] + results3[0][2],
  })
}
